Imports System.Text

Public Class VBTORenderEngine
    Inherits VBAbstractRenderEngine

    Public Sub New(ByVal u As UpdateProgress, ByVal s As UpdateStatus)
        MyBase.New(u, s, GetType(SQL))
    End Sub

    Protected Overrides Function FormatFilename(ByVal tableName As String) As String
        Return tableName & "TO"
    End Function

    Protected Overrides Function RenderPrefix(ByVal t As Table) As String
        Dim sb As New StringBuilder
        sb = sb.Append("Imports pixolut.BizBlox").Append(vbCrLf)
        If Me.Project.EnableTODataContractInfo Then
            sb = sb.Append("Imports System.Runtime.Serialization").Append(vbCrLf).Append(vbCrLf)
            sb = sb.Append("<DataContract> _").Append(vbCrLf)
        Else
            sb = sb.Append(vbCrLf)
        End If
        sb = sb.Append("Public Class ").Append(FormatFilename(t.TableName)).Append(vbCrLf)
        sb = sb.Append(vbCrLf)
        Return sb.ToString()
    End Function

    Protected Overrides Function RenderPostfix(ByVal t As Table) As String
        Dim sb As New StringBuilder
        sb = sb.Append(vbCrLf)
        sb = sb.Append("End Class").Append(vbCrLf)
        Return sb.ToString()
    End Function

    Protected Overrides Function RenderColumn(ByVal t As Table, ByVal index As Integer) As String
        Dim sb As New StringBuilder
        sb = sb.Append(vbCrLf)
        sb = sb.Append("    Private m_").Append(t(index).ColumnName).Append(" As ").Append(t(index).DataType).Append(vbCrLf)
        If Me.Project.EnableTODataContractInfo Then
            sb = sb.Append("    <DataMember(Order=" & index & ")> _").Append(vbCrLf)
        End If
        sb = sb.Append("    Public Property ").Append(t(index).ColumnName).Append("() As ").Append(t(index).DataType).Append(vbCrLf)
        sb = sb.Append("        Get").Append(vbCrLf)
        sb = sb.Append("            Return m_").Append(t(index).ColumnName).Append(vbCrLf)
        sb = sb.Append("        End Get").Append(vbCrLf)
        sb = sb.Append("        Set(ByVal Value As ").Append(t(index).DataType).Append(")").Append(vbCrLf)
        sb = sb.Append("            m_").Append(t(index).ColumnName).Append(" = Value").Append(vbCrLf)
        sb = sb.Append("        End Set").Append(vbCrLf)
        sb = sb.Append("    End Property").Append(vbCrLf).Append(vbCrLf)
        Return sb.ToString()
    End Function

    Protected Overrides Function RenderForeignColumn(ByVal t As Table, ByVal index As Integer) As String
        Return ""
    End Function

    Protected Overrides Function RenderElements(ByVal t As Table) As String
        Return ""
    End Function
End Class
